package xyz.xpman.prisonerfitness.entity;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.os.CancellationSignal;

import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

@SuppressWarnings("unused")
public class Condition {
    /**
     * where 条件顺序
     * 更新字段value时，不改变字段条件顺序
     */
    LinkedHashSet<String> condSerialNo;
    // condition attrs
    ContentValues attrs;


    Boolean distinct;

    String table;
    String[] column;
    String selection;
    String[] selectionArgs;

    String groupB;
    String having;
    String orderBy;
    String limit;

    CancellationSignal cancellationSign;




    // sql common attr for select
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -




    public Boolean isDistinct() {
        return distinct;
    }

    public String getTable() {
        return table;
    }

    public String[] getColumn() {
        return column;
    }

    public String getSelection() {
        return selection;
    }

    public String[] getSelectionArgs() {
        return selectionArgs;
    }

    public String getGroupB() {
        return groupB;
    }

    public String getHaving() {
        return having;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public String getLimit() {
        return limit;
    }

    public CancellationSignal getCancellationSign() {
        return cancellationSign;
    }




    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


    private void addCondAttr(String key) {
        condSerialNo.add(key);
    }

    private void removeCondAttr(String key) {
        condSerialNo.remove(key);
    }


    // put method proxy for ContentValues
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -




    public void put(String key, String value) {
        attrs.put(key, value);
        addCondAttr(key);
    }

    public void putAll(Condition other) {
        attrs.putAll(other.attrs);
    }




    public void put(String key, Byte value) {
        attrs.put(key, value);
        addCondAttr(key);
    }

    public void put(String key, Short value) {
        attrs.put(key, value);
        addCondAttr(key);
    }

    public void put(String key, Integer value) {
        attrs.put(key, value);
        addCondAttr(key);
    }

    public void put(String key, Long value) {
        attrs.put(key, value);
        addCondAttr(key);
    }

    public void put(String key, Float value) {
        attrs.put(key, value);
        addCondAttr(key);
    }

    public void put(String key, Double value) {
        attrs.put(key, value);
        addCondAttr(key);
    }

    public void put(String key, Boolean value) {
        attrs.put(key, value);
        addCondAttr(key);
    }

    public void put(String key, byte[] value) {
        attrs.put(key, value);
        addCondAttr(key);
    }



    public void putNull(String key) {
        attrs.putNull(key);
        addCondAttr(key);
    }




    // get method proxy for ContentValues
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


    public Object get(String key) {
        return attrs.get(key);
    }

    public String getAsString(String key) {
        return attrs.getAsString(key);
    }

    public Long getAsLong(String key) {
        return attrs.getAsLong(key);
    }

    public Integer getAsInteger(String key) {
        return attrs.getAsInteger(key);
    }

    public Short getAsShort(String key) {
        return attrs.getAsShort(key);
    }

    public Byte getAsByte(String key) {
        return attrs.getAsByte(key);
    }

    public Double getAsDouble(String key) {
        return attrs.getAsDouble(key);
    }

    public Float getAsFloat(String key) {
        return attrs.getAsFloat(key);
    }

    public Boolean getAsBoolean(String key) {
        return attrs.getAsBoolean(key);
    }

    public byte[] getAsByteArray(String key) {
        return attrs.getAsByteArray(key);
    }


    // 杂项 method proxy for ContentValues
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


    public boolean containsKey(String key) {
        return attrs.containsKey(key);
    }

    public void remove(String key) {
        attrs.remove(key);
        removeCondAttr(key);
    }

    public Set<String> keySet() {
        return attrs.keySet();
    }

    public Set<Map.Entry<String, Object>> valueSet() {
        return attrs.valueSet();
    }

    public int size() {
        return attrs.size();
    }

    @SuppressLint("NewApi")
    public boolean isEmpty() {
        return attrs.isEmpty();
    }

}
